from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-04-03 14:02:08.348487
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Sun, 03, Apr, 2022
Time: 14:02:14
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -48.8109
Nobs: 615.000 HQIC: -49.2064
Log likelihood: 7444.51 FPE: 3.31647e-22
AIC: -49.4580 Det(Omega_mle): 2.86835e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.340807 0.065160 5.230 0.000
L1.Burgenland 0.106042 0.040184 2.639 0.008
L1.Kärnten -0.110595 0.021024 -5.260 0.000
L1.Niederösterreich 0.194597 0.084010 2.316 0.021
L1.Oberösterreich 0.118454 0.082745 1.432 0.152
L1.Salzburg 0.259350 0.042623 6.085 0.000
L1.Steiermark 0.041495 0.056196 0.738 0.460
L1.Tirol 0.104419 0.045379 2.301 0.021
L1.Vorarlberg -0.066289 0.040093 -1.653 0.098
L1.Wien 0.018475 0.073723 0.251 0.802
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.052000 0.139713 0.372 0.710
L1.Burgenland -0.038198 0.086162 -0.443 0.658
L1.Kärnten 0.042059 0.045078 0.933 0.351
L1.Niederösterreich -0.202199 0.180131 -1.123 0.262
L1.Oberösterreich 0.455185 0.177419 2.566 0.010
L1.Salzburg 0.282731 0.091390 3.094 0.002
L1.Steiermark 0.112922 0.120493 0.937 0.349
L1.Tirol 0.306127 0.097299 3.146 0.002
L1.Vorarlberg 0.026846 0.085966 0.312 0.755
L1.Wien -0.028748 0.158075 -0.182 0.856
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.195488 0.033282 5.874 0.000
L1.Burgenland 0.088441 0.020525 4.309 0.000
L1.Kärnten -0.007169 0.010738 -0.668 0.504
L1.Niederösterreich 0.243430 0.042910 5.673 0.000
L1.Oberösterreich 0.160567 0.042264 3.799 0.000
L1.Salzburg 0.040048 0.021771 1.840 0.066
L1.Steiermark 0.027672 0.028704 0.964 0.335
L1.Tirol 0.082542 0.023178 3.561 0.000
L1.Vorarlberg 0.054225 0.020479 2.648 0.008
L1.Wien 0.116661 0.037656 3.098 0.002
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.114205 0.033321 3.427 0.001
L1.Burgenland 0.042699 0.020549 2.078 0.038
L1.Kärnten -0.013068 0.010751 -1.215 0.224
L1.Niederösterreich 0.173419 0.042961 4.037 0.000
L1.Oberösterreich 0.334757 0.042314 7.911 0.000
L1.Salzburg 0.100048 0.021796 4.590 0.000
L1.Steiermark 0.113338 0.028737 3.944 0.000
L1.Tirol 0.090766 0.023206 3.911 0.000
L1.Vorarlberg 0.060723 0.020503 2.962 0.003
L1.Wien -0.017354 0.037700 -0.460 0.645
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.120370 0.062409 1.929 0.054
L1.Burgenland -0.046168 0.038488 -1.200 0.230
L1.Kärnten -0.045392 0.020136 -2.254 0.024
L1.Niederösterreich 0.138391 0.080463 1.720 0.085
L1.Oberösterreich 0.162186 0.079252 2.046 0.041
L1.Salzburg 0.284403 0.040823 6.967 0.000
L1.Steiermark 0.059790 0.053823 1.111 0.267
L1.Tirol 0.159183 0.043463 3.663 0.000
L1.Vorarlberg 0.097952 0.038400 2.551 0.011
L1.Wien 0.071966 0.070611 1.019 0.308
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.064769 0.048798 1.327 0.184
L1.Burgenland 0.025487 0.030094 0.847 0.397
L1.Kärnten 0.053117 0.015745 3.374 0.001
L1.Niederösterreich 0.192758 0.062915 3.064 0.002
L1.Oberösterreich 0.331584 0.061968 5.351 0.000
L1.Salzburg 0.035992 0.031920 1.128 0.260
L1.Steiermark 0.011971 0.042085 0.284 0.776
L1.Tirol 0.120901 0.033984 3.558 0.000
L1.Vorarlberg 0.066841 0.030026 2.226 0.026
L1.Wien 0.097863 0.055211 1.773 0.076
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.172527 0.058776 2.935 0.003
L1.Burgenland 0.004743 0.036248 0.131 0.896
L1.Kärnten -0.065807 0.018964 -3.470 0.001
L1.Niederösterreich -0.104793 0.075780 -1.383 0.167
L1.Oberösterreich 0.205841 0.074639 2.758 0.006
L1.Salzburg 0.054473 0.038447 1.417 0.157
L1.Steiermark 0.247148 0.050691 4.876 0.000
L1.Tirol 0.502103 0.040933 12.266 0.000
L1.Vorarlberg 0.063914 0.036165 1.767 0.077
L1.Wien -0.077481 0.066501 -1.165 0.244
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.155250 0.065147 2.383 0.017
L1.Burgenland -0.002359 0.040177 -0.059 0.953
L1.Kärnten 0.062542 0.021020 2.975 0.003
L1.Niederösterreich 0.169181 0.083994 2.014 0.044
L1.Oberösterreich -0.055998 0.082730 -0.677 0.498
L1.Salzburg 0.208170 0.042615 4.885 0.000
L1.Steiermark 0.140128 0.056185 2.494 0.013
L1.Tirol 0.058362 0.045370 1.286 0.198
L1.Vorarlberg 0.147174 0.040085 3.672 0.000
L1.Wien 0.120276 0.073709 1.632 0.103
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.386320 0.038337 10.077 0.000
L1.Burgenland -0.004268 0.023643 -0.181 0.857
L1.Kärnten -0.020921 0.012369 -1.691 0.091
L1.Niederösterreich 0.202743 0.049427 4.102 0.000
L1.Oberösterreich 0.231482 0.048683 4.755 0.000
L1.Salzburg 0.036601 0.025077 1.460 0.144
L1.Steiermark -0.014571 0.033063 -0.441 0.659
L1.Tirol 0.089316 0.026699 3.345 0.001
L1.Vorarlberg 0.051517 0.023589 2.184 0.029
L1.Wien 0.044612 0.043375 1.029 0.304
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.036828 0.109731 0.173035 0.139647 0.102349 0.081848 0.035941 0.211211
Kärnten 0.036828 1.000000 -0.026041 0.130857 0.049233 0.085127 0.443568 -0.066550 0.089760
Niederösterreich 0.109731 -0.026041 1.000000 0.314111 0.121331 0.275042 0.068605 0.154742 0.292902
Oberösterreich 0.173035 0.130857 0.314111 1.000000 0.213648 0.297498 0.167039 0.138445 0.239810
Salzburg 0.139647 0.049233 0.121331 0.213648 1.000000 0.124935 0.093013 0.105980 0.125272
Steiermark 0.102349 0.085127 0.275042 0.297498 0.124935 1.000000 0.135062 0.108957 0.038016
Tirol 0.081848 0.443568 0.068605 0.167039 0.093013 0.135062 1.000000 0.065177 0.150950
Vorarlberg 0.035941 -0.066550 0.154742 0.138445 0.105980 0.108957 0.065177 1.000000 -0.003045
Wien 0.211211 0.089760 0.292902 0.239810 0.125272 0.038016 0.150950 -0.003045 1.000000